﻿Imports System
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Text
<Serializable()> Public Class NewPostResult
    Private m_PostSuperscale As New PostSuperscale
    Private m_PostMax As New PostMax
    Private m_PostPost As New PostPost
    
    
    Property PostSuperscale() As PostSuperscale
        Get
            Return Me.m_PostSuperscale
        End Get
        Set(ByVal value As PostSuperscale)
            Me.m_PostSuperscale = value
        End Set
    End Property
    Property PostMax() As PostMax
        Get
            Return Me.m_PostMax
        End Get
        Set(ByVal value As PostMax)
            Me.m_PostMax = value
        End Set
    End Property
    Property PostPost() As PostPost
        Get
            Return Me.m_PostPost
        End Get
        Set(ByVal value As PostPost)
            Me.m_PostPost = value
        End Set
    End Property
    
    Public Function StringToDate(ByVal strTime As String) As DateTime
        strTime = strTime.PadLeft(8, "0")
        Dim strYear As String = strTime.Substring(0, 2)
        If CInt(strYear) < 10 Then '50年代以前的数据均为2000年
            strYear = "200" & CInt(strYear)
        ElseIf CInt(strYear) <= 50 Then
            strYear = "20" & CInt(strYear)
        Else
            strYear = "19" & CInt(strYear)
        End If
        '由于有aermet2种记录格式：一种是从0点到23点，另一种是从1点到24点。应在这里进行判断。如果用24小时表示，则应表示为第2天的0点。
        Dim nyear As Integer = CInt(strYear)
        Dim nday As Integer = CInt(strTime.Substring(2, 2))
        Dim nMonth As Integer = CInt(strTime.Substring(4, 2))
        Dim nHour As Integer = CInt(strTime.Substring(6, 2))
        Dim DateTime As Date
        If nHour = 24 Then
            DateTime = New DateTime(nyear, nday, nMonth, 23, 0, 0)  '读取时间,并减1小时
            DateTime = DateTime.AddHours(1)
        Else
            DateTime = New DateTime(nyear, nday, nMonth, nHour, 0, 0)
        End If
        Return DateTime
    End Function
    ''' <summary>
    ''' 只计算字符串的天
    ''' </summary>
    ''' <param name="strTime"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function StringToDay(ByVal strTime As String) As DateTime
        strTime = strTime.PadLeft(8, "0")
        Dim strYear As String = strTime.Substring(0, 2)
        If CInt(strYear) < 10 Then '50年代以前的数据均为2000年
            strYear = "200" & CInt(strYear)
        ElseIf CInt(strYear) <= 50 Then
            strYear = "20" & CInt(strYear)
        Else
            strYear = "19" & CInt(strYear)
        End If
        '由于有aermet2种记录格式：一种是从0点到23点，另一种是从1点到24点。应在这里进行判断。如果用24小时表示，则应表示为第2天的0点。
        Dim nyear As Integer = CInt(strYear)
        Dim nday As Integer = CInt(strTime.Substring(2, 2))
        Dim nMonth As Integer = CInt(strTime.Substring(4, 2))
        Dim nHour As Integer = CInt(strTime.Substring(6, 2))
        Dim DateTime As Date
        DateTime = New DateTime(nyear, nday, nMonth, 0, 0, 0)
        Return DateTime
    End Function

    ''' <summary>
    ''' 通过给定期间的POST文件求出超标率，最大持续超标时间。
    ''' </summary>
    ''' <param name="Control">控制选项</param>
    ''' <param name="Receptor">接受点</param>
    ''' <remarks></remarks>
    Public Function GetDataFromPostBin(ByVal Control As Control, ByVal Receptor As Receptor, ByVal DEPOS As Boolean, ByVal strMaxDate As String, ByVal strFileName As String, ByVal version As String) As Boolean
        '获取典型小时和典型日
        GetMaxFromPostBin(Control, Receptor, DEPOS, strMaxDate, strFileName, version)
        '获取超标次数和最大超标时间
        GetOverDataFromPostBin(Control, Receptor, DEPOS, strFileName, version)
    End Function
    Public Function GetFirstTime(ByVal strFileName As String) As String
        Dim dateD As String = ""
        Dim binReader As New BinaryReader(File.Open(strFileName, FileMode.Open)) '打开要读取的文件
        Try
            '读取POST文件
            Dim Postvalue(128 - 1) As Byte
            binReader.BaseStream.Position = 0
            Dim count As Integer = binReader.Read(Postvalue, 0, 128) '获取指定位置的数据
            Dim Index As Integer = 0
            Index = 0
            Index += 4 '跳过头文件
            '跳到给定个数的位置
            dateD = BitConverter.ToInt32(Postvalue, Index) '读取日期
        Catch ex As Exception
            binReader.Close()
            Return ""
        Finally
            binReader.Close()
        End Try
        Return dateD
    End Function
    ''' <summary>
    ''' 获取典型小时数据
    ''' </summary>
    ''' <param name="Control">控制选项</param>
    ''' <param name="Receptor">接受点</param>
    ''' <remarks></remarks>
    Public Sub GetMaxFromPostBin(ByVal Control As Control, ByVal Receptor As Receptor, ByVal DEPOS As Boolean, ByVal strMaxDate As String, ByVal strFileName As String, ByVal version As String)
        '获取典型小时和典型日

        If My.Computer.FileSystem.FileExists(strFileName) Then

            Dim strFirstTime As String = GetFirstTime(strFileName)
            Dim FirstTime As DateTime = StringToDate(strFirstTime) '开始时间
            If strMaxDate = "00000000" Then
                Exit Sub
            End If
            Dim TypeHour As DateTime = StringToDate(strMaxDate) '典型小时
            Dim nIndex As Integer = (TypeHour - FirstTime).TotalHours
            Dim OnePostBin As PostFineBinResult = GetDataPostBin(Control, Receptor, DEPOS, nIndex, strFileName, version)
            ReDim Me.m_PostMax.GridMax(Receptor.SubGridCart(0).Ynum - 1, Receptor.SubGridCart(0).Xnum - 1)
            For i As Integer = 0 To Receptor.SubGridCart(0).Ynum - 1
                For j As Integer = 0 To Receptor.SubGridCart(0).Xnum - 1
                    Me.m_PostMax.GridMax(i, j) = OnePostBin.m_GridData(i, j).con
                Next
            Next
            ReDim Me.m_PostMax.SubGridMax(Receptor.SubGridCart.Length - 1)
            For isub As Integer = 0 To Receptor.SubGridCart.Length - 1
                ReDim Me.m_PostMax.SubGridMax(isub)(Receptor.SubGridCart(isub).Ynum - 1, Receptor.SubGridCart(isub).Xnum - 1)
                For i As Integer = 0 To Receptor.SubGridCart(isub).Ynum - 1
                    For j As Integer = 0 To Receptor.SubGridCart(isub).Xnum - 1
                        Me.m_PostMax.SubGridMax(isub)(i, j) = OnePostBin.m_SubGridData(isub)(i, j).con
                    Next
                Next
            Next
        End If
    End Sub
    ''' <summary>
    ''' 通过给定1小时的POST文件求出超标率，最大持续超标时间。
    ''' </summary>
    ''' <param name="Control">控制选项</param>
    ''' <param name="Receptor">接受点</param>
    ''' <remarks></remarks>
    Public Sub GetOverDataFromPostBin(ByVal Control As Control, ByVal Receptor As Receptor, ByVal DEPOS As Boolean, ByVal strFileName As String, ByVal version As String)
        ''初始化关心点设置-----------------
        'ReDim Me.m_PostSuperscale.CareSuperScale(Receptor.DiscCarts.Length - 1)
        'Dim nCountCare(Receptor.DiscCarts.Length - 1) As Integer
        'Dim MaxOverTimeCare(Receptor.DiscCarts.Length - 1) As OverTime
        'Dim OverTimeCare(Receptor.DiscCarts.Length - 1) As OverTime
        'Dim nHourCare(Receptor.DiscCarts.Length - 1) As Integer
        'Dim conCare(Receptor.DiscCarts.Length - 1) As Double

        'For j As Integer = 0 To Receptor.DiscCarts.Length - 1
        '    MaxOverTimeCare(j) = New OverTime
        '    OverTimeCare(j) = New OverTime
        'Next
        ''初始化网格点设置-------------
        'ReDim Me.m_PostSuperscale.GridSuperScale(Receptor.SubGridCart(0).Ynum - 1, Receptor.SubGridCart(0).Xnum - 1)
        'Dim MaxBackGrid(Receptor.SubGridCart(0).Ynum - 1, Receptor.SubGridCart(0).Xnum - 1) As Double
        'Dim nCountGrid(Receptor.SubGridCart(0).Ynum - 1, Receptor.SubGridCart(0).Xnum - 1) As Integer
        'Dim MaxOverTimeGrid(Receptor.SubGridCart(0).Ynum - 1, Receptor.SubGridCart(0).Xnum - 1) As OverTime
        'Dim OverTimeGrid(Receptor.SubGridCart(0).Ynum - 1, Receptor.SubGridCart(0).Xnum - 1) As OverTime
        'Dim nHourGrid(Receptor.SubGridCart(0).Ynum - 1, Receptor.SubGridCart(0).Xnum - 1) As Integer
        'Dim conGrid(Receptor.SubGridCart(0).Ynum - 1, Receptor.SubGridCart(0).Xnum - 1) As Double
        'For j As Integer = 0 To Receptor.SubGridCart(0).Ynum - 1
        '    For k As Integer = 0 To Receptor.SubGridCart(0).Xnum - 1
        '        MaxOverTimeGrid(j, k) = New OverTime
        '        OverTimeGrid(j, k) = New OverTime
        '        Me.m_PostSuperscale.GridSuperScale(j, k) = New Superscale
        '        MaxBackGrid(j, k) = Me.m_PostSuperscale.AverageBackCon
        '        Me.m_PostSuperscale.GridSuperScale(j, k).BackCon = Me.m_PostSuperscale.AverageBackCon
        '    Next
        'Next

        ''初始化网格点设置-------------
        'ReDim Me.m_PostSuperscale.SubGridSuperScale(Receptor.SubGridCart.Length - 1)
        'Dim SubMaxBackGrid(Receptor.SubGridCart.Length - 1)(,) As Double
        'Dim SubnCountGrid(Receptor.SubGridCart.Length - 1)(,) As Integer
        'Dim SubMaxOverTimeGrid(Receptor.SubGridCart.Length - 1)(,) As OverTime
        'Dim SubOverTimeGrid(Receptor.SubGridCart.Length - 1)(,) As OverTime
        'Dim SubnHourGrid(Receptor.SubGridCart.Length - 1)(,) As Integer
        'Dim SubconGrid(Receptor.SubGridCart.Length - 1)(,) As Double
        'For iSub As Integer = 0 To Receptor.SubGridCart.Length - 1
        '    ReDim Me.m_PostSuperscale.SubGridSuperScale(iSub)(Receptor.SubGridCart(iSub).Ynum - 1, Receptor.SubGridCart(iSub).Xnum - 1)
        '    ReDim SubMaxBackGrid(iSub)(Receptor.SubGridCart(iSub).Ynum - 1, Receptor.SubGridCart(iSub).Xnum - 1)
        '    ReDim SubnCountGrid(iSub)(Receptor.SubGridCart(iSub).Ynum - 1, Receptor.SubGridCart(iSub).Xnum - 1)
        '    ReDim SubMaxOverTimeGrid(iSub)(Receptor.SubGridCart(iSub).Ynum - 1, Receptor.SubGridCart(iSub).Xnum - 1)
        '    ReDim SubOverTimeGrid(iSub)(Receptor.SubGridCart(iSub).Ynum - 1, Receptor.SubGridCart(iSub).Xnum - 1)
        '    ReDim SubnHourGrid(iSub)(Receptor.SubGridCart(iSub).Ynum - 1, Receptor.SubGridCart(iSub).Xnum - 1)
        '    ReDim SubconGrid(iSub)(Receptor.SubGridCart(iSub).Ynum - 1, Receptor.SubGridCart(iSub).Xnum - 1)
        '    For j As Integer = 0 To Receptor.SubGridCart(iSub).Ynum - 1
        '        For k As Integer = 0 To Receptor.SubGridCart(iSub).Xnum - 1
        '            SubMaxOverTimeGrid(iSub)(j, k) = New OverTime
        '            SubOverTimeGrid(iSub)(j, k) = New OverTime
        '            Me.m_PostSuperscale.SubGridSuperScale(iSub)(j, k) = New Superscale
        '            SubMaxBackGrid(iSub)(j, k) = Me.m_PostSuperscale.AverageBackCon
        '            Me.m_PostSuperscale.SubGridSuperScale(iSub)(j, k).BackCon = Me.m_PostSuperscale.AverageBackCon
        '        Next
        '    Next
        'Next

        'If My.Computer.FileSystem.FileExists(strFileName) Then
        '    Dim nCount As Integer = GetDataCount(Control, Receptor, DEPOS, strFileName, version)
        '    For nIndex As Integer = 0 To nCount - 1
        '        Dim OnePostBin As PostFineBinResult = GetDataPostBin(Control, Receptor, DEPOS, nIndex, strFileName, version)
        '        For j As Integer = 0 To Receptor.DiscCarts.Length - 1
        '            '计算关心点小时超标情况
        '            '-------------------------------------------------------------------------------
        '            '求小时平均的
        '            '-------------------------------------------------------------------------------
        '            '标准浓度和背景浓度
        '            '先设置关心点的小时浓度

        '            If Me.m_PostSuperscale.CareSuperScale(j).BackCon = 0 Then
        '                '浓度背景值。取最大值
        '                Me.m_PostSuperscale.CareSuperScale(j).SuperCount = 0 '超标次数
        '                Me.m_PostSuperscale.CareSuperScale(j).SuperRate = 0 '超标率
        '            Else
        '                conCare(j) = OnePostBin.m_CareData(j).con / 1000 + Me.m_PostSuperscale.CareSuperScale(j).BackCon
        '                If conCare(j) > Me.m_PostSuperscale.CareSuperScale(j).BackCon Then
        '                    If OverTimeCare(j).nTime = 0 Then
        '                        OverTimeCare(j) = New OverTime
        '                        OverTimeCare(j).StartTime = OnePostBin.m_dateD
        '                    End If

        '                    OverTimeCare(j).nTime += 1
        '                    nCountCare(j) += 1
        '                End If
        '                If OverTimeCare(j).nTime > 0 Then
        '                    OverTimeCare(j).EndTime = OnePostBin.m_dateD
        '                End If
        '                If OverTimeCare(j).nTime > MaxOverTimeCare(j).nTime Then
        '                    MaxOverTimeCare(j).StartTime = OverTimeCare(j).StartTime
        '                    MaxOverTimeCare(j).EndTime = OverTimeCare(j).EndTime
        '                    MaxOverTimeCare(j).nTime = OverTimeCare(j).nTime
        '                End If
        '                If conCare(j) <= Me.m_PostSuperscale.StandardCon Then
        '                    OverTimeCare(j) = New OverTime
        '                End If
        '                nHourCare(j) += 1
        '                Me.m_PostSuperscale.CareSuperScale(j).SuperCount = nCountCare(j) '超标次数
        '                Me.m_PostSuperscale.CareSuperScale(j).SuperRate = nCountCare(j) / nHourCare(j)  '超标率
        '                If MaxOverTimeCare(j).nTime > 0 Then
        '                    Me.m_PostSuperscale.CareSuperScale(j).MaxOverTime = MaxOverTimeCare(j)
        '                End If
        '            End If
        '        Next
        '        '计算网格点小时超标情况
        '        If Receptor.SubGridCart(0).Selected = True Then
        '            '网格超标情况
        '            For j As Integer = 0 To Receptor.SubGridCart(0).Ynum - 1
        '                For k As Integer = 0 To Receptor.SubGridCart(0).Xnum - 1
        '                    Dim ConStandard As Double = Me.m_PostSuperscale.StandardCon
        '                    If ConStandard = 0 Then '如果标准浓度为0，没有超标
        '                        '浓度背景值。取最大值
        '                        Me.m_PostSuperscale.GridSuperScale(j, k).SuperCount = 0 '超标次数
        '                        Me.m_PostSuperscale.GridSuperScale(j, k).SuperRate = 0 '超标率
        '                    Else
        '                        conGrid(j, k) = OnePostBin.m_GridData(j, k).con / 1000 + MaxBackGrid(j, k)
        '                        If conGrid(j, k) > ConStandard Then
        '                            If OverTimeGrid(j, k).nTime = 0 Then
        '                                OverTimeGrid(j, k) = New OverTime
        '                                OverTimeGrid(j, k).StartTime = OnePostBin.m_dateD
        '                            End If

        '                            OverTimeGrid(j, k).nTime += 1
        '                            nCountGrid(j, k) += 1
        '                        End If
        '                        If OverTimeGrid(j, k).nTime > 0 Then
        '                            OverTimeGrid(j, k).EndTime = OnePostBin.m_dateD
        '                        End If
        '                        If OverTimeGrid(j, k).nTime > MaxOverTimeGrid(j, k).nTime Then
        '                            MaxOverTimeGrid(j, k).StartTime = OverTimeGrid(j, k).StartTime
        '                            MaxOverTimeGrid(j, k).EndTime = OverTimeGrid(j, k).EndTime
        '                            MaxOverTimeGrid(j, k).nTime = OverTimeGrid(j, k).nTime
        '                        End If
        '                        If conGrid(j, k) <= ConStandard Then
        '                            OverTimeGrid(j, k) = New OverTime
        '                        End If
        '                        nHourGrid(j, k) += 1
        '                        Me.m_PostSuperscale.GridSuperScale(j, k).SuperCount = nCountGrid(j, k) '超标次数
        '                        Me.m_PostSuperscale.GridSuperScale(j, k).SuperRate = nCountGrid(j, k) / nHourGrid(j, k)  '超标率
        '                        If MaxOverTimeGrid(j, k).nTime > 0 Then
        '                            Me.m_PostSuperscale.GridSuperScale(j, k).MaxOverTime = MaxOverTimeGrid(j, k)
        '                        End If
        '                    End If
        '                Next
        '            Next
        '            For iSub As Integer = 0 To Receptor.SubGridCart.Length - 1 '嵌套网格
        '                If Receptor.SubGridCart(iSub).Selected = True Then
        '                    For j As Integer = 0 To Receptor.SubGridCart(iSub).Ynum - 1
        '                        For k As Integer = 0 To Receptor.SubGridCart(iSub).Xnum - 1
        '                            Dim ConStandard As Double = Me.m_PostSuperscale.StandardCon
        '                            If ConStandard = 0 Then '如果标准浓度为0，没有超标
        '                                '浓度背景值。取最大值
        '                                Me.m_PostSuperscale.SubGridSuperScale(iSub)(j, k).SuperCount = 0 '超标次数
        '                                Me.m_PostSuperscale.SubGridSuperScale(iSub)(j, k).SuperRate = 0 '超标率
        '                            Else
        '                                SubconGrid(iSub)(j, k) = OnePostBin.m_SubGridData(iSub)(j, k).con / 1000 + SubMaxBackGrid(iSub)(j, k)
        '                                If SubconGrid(iSub)(j, k) > ConStandard Then
        '                                    If SubOverTimeGrid(iSub)(j, k).nTime = 0 Then
        '                                        SubOverTimeGrid(iSub)(j, k) = New OverTime
        '                                        SubOverTimeGrid(iSub)(j, k).StartTime = OnePostBin.m_dateD
        '                                    End If

        '                                    SubOverTimeGrid(iSub)(j, k).nTime += 1
        '                                    SubnCountGrid(iSub)(j, k) += 1
        '                                End If
        '                                If SubOverTimeGrid(iSub)(j, k).nTime > 0 Then
        '                                    SubOverTimeGrid(iSub)(j, k).EndTime = OnePostBin.m_dateD
        '                                End If
        '                                If SubOverTimeGrid(iSub)(j, k).nTime > SubMaxOverTimeGrid(iSub)(j, k).nTime Then
        '                                    SubMaxOverTimeGrid(iSub)(j, k).StartTime = SubOverTimeGrid(iSub)(j, k).StartTime
        '                                    SubMaxOverTimeGrid(iSub)(j, k).EndTime = SubOverTimeGrid(iSub)(j, k).EndTime
        '                                    SubMaxOverTimeGrid(iSub)(j, k).nTime = SubOverTimeGrid(iSub)(j, k).nTime
        '                                End If
        '                                If SubconGrid(iSub)(j, k) <= ConStandard Then
        '                                    SubOverTimeGrid(iSub)(j, k) = New OverTime
        '                                End If
        '                                SubnHourGrid(iSub)(j, k) += 1
        '                                Me.m_PostSuperscale.SubGridSuperScale(iSub)(j, k).SuperCount = SubnCountGrid(iSub)(j, k) '超标次数
        '                                Me.m_PostSuperscale.SubGridSuperScale(iSub)(j, k).SuperRate = SubnCountGrid(iSub)(j, k) / SubnHourGrid(iSub)(j, k)  '超标率
        '                                If SubMaxOverTimeGrid(iSub)(j, k).nTime > 0 Then
        '                                    Me.m_PostSuperscale.SubGridSuperScale(iSub)(j, k).MaxOverTime = SubMaxOverTimeGrid(iSub)(j, k)
        '                                End If
        '                            End If
        '                        Next
        '                    Next
        '                End If
        '            Next
        '        End If
        '    Next
        'End If
    End Sub

    ''' <summary>
    ''' 获取记录的个数
    ''' </summary>
    ''' <param name="Control">控制选项</param>
    ''' <param name="Receptor">接受点</param>
    ''' <remarks></remarks>
    Public Function GetDataCount(ByVal Control As Control, ByVal Receptor As Receptor, ByVal DEPOS As Boolean, ByVal strFileName As String, ByVal version As String) As Integer
        Dim nVer As Integer = 0
        If version = "07026" Then
            nVer = 1
        ElseIf version = "09292" Then
            nVer = 2
        End If


        '只获取1小时或24小时的浓度
        Dim nCount As Long = 0
        Dim OnePostResult As New PostFineBinResult '保存单个记录的数据
        If My.Computer.FileSystem.FileExists(strFileName) Then
            Dim OneLeng As Long = 0
            Dim Index As Long = 0
            Index += 4 '跳过头文件
            Index += 4 + 4 + 8 '跳过平均小时数和所在组的ID
            If Receptor.SubGridCart(0).Selected = True Then
                Index += 4 * Receptor.SubGridCart(0).Ynum * Receptor.SubGridCart(0).Xnum * nVer
            End If
            '嵌套网格
            If Receptor.SubGridCart.Length > 0 Then
                For iSub As Integer = 0 To Receptor.SubGridCart.Length - 1
                    If Receptor.SubGridCart(iSub).Selected = True Then
                        Index += 4 * Receptor.SubGridCart(iSub).Ynum * Receptor.SubGridCart(iSub).Xnum * nVer
                    End If
                Next
            End If

            Index += 4 * Receptor.DiscCarts.Length * nVer  '关心点浓度点位
            If Receptor.SubGridCart(0).Selected = True Then
                If DEPOS = True Then '干湿沉积
                    Index += 4 * 3 * Receptor.SubGridCart(0).Ynum * Receptor.SubGridCart(0).Xnum * nVer
                End If
            End If
            '嵌套网格
            If Receptor.SubGridCart.Length > 0 Then
                For iSub As Integer = 0 To Receptor.SubGridCart.Length - 1
                    If Receptor.SubGridCart(iSub).Selected = True Then
                        If DEPOS = True Then '干湿沉积
                            Index += 4 * 3 * Receptor.SubGridCart(iSub).Ynum * Receptor.SubGridCart(iSub).Xnum * nVer
                        End If
                    End If
                Next
            End If
            If DEPOS = True Then '干湿沉积
                Index += 4 * 3 * Receptor.DiscCarts.Length * nVer
            End If
            Index += 4
            OneLeng = Index  '求得每个记录的长度

            Dim binReader As New BinaryReader(File.Open(strFileName, FileMode.Open)) '打开要读取的文件
            Try
                '读取POST文件
                nCount = binReader.BaseStream.Length / OneLeng
            Catch ex As Exception
                binReader.Close()
                Return 0
            Finally
                binReader.Close()
            End Try
        End If
        Return nCount
    End Function
    ''' <summary>
    ''' 根据给定的文件得到一个记录的数据
    ''' </summary>
    ''' <param name="Control">控制选项</param>
    ''' <param name="Receptor">接受点</param>
    ''' <remarks></remarks>
    Public Function GetDataPostBin(ByVal Control As Control, ByVal Receptor As Receptor, ByVal DEPOS As Boolean, ByVal IndexTime As Long, ByVal strFileName As String, ByVal version As String) As PostFineBinResult
        Dim nVer As Integer = 0
        If version = "07026" Then
            nVer = 1
        ElseIf version = "09292" Then
            nVer = 2
        End If


        Dim OnePostResult As New PostFineBinResult '保存单个记录的数据
        If My.Computer.FileSystem.FileExists(strFileName) Then
            Dim OneLeng As Long = 0
            Dim Index As Long = 0
            Index += 4 '跳过头文件
            Index += 4 + 4 + 8  '跳过平均小时数和所在组的ID
            If Receptor.SubGridCart(0).Selected = True Then
                Index += 4 * Receptor.SubGridCart(0).Ynum * Receptor.SubGridCart(0).Xnum * nVer
            End If
            '嵌套网格
            If Receptor.SubGridCart.Length > 0 Then
                For iSub As Integer = 0 To Receptor.SubGridCart.Length - 1
                    If Receptor.SubGridCart(iSub).Selected = True Then
                        Index += 4 * Receptor.SubGridCart(iSub).Ynum * Receptor.SubGridCart(iSub).Xnum * nVer
                    End If
                Next
            End If

            Index += 4 * Receptor.DiscCarts.Length * nVer '关心点浓度点位
            If Receptor.SubGridCart(0).Selected = True Then
                If DEPOS = True Then '干湿沉积
                    Index += 4 * 3 * Receptor.SubGridCart(0).Ynum * Receptor.SubGridCart(0).Xnum * nVer
                End If
            End If
            '嵌套网格
            If Receptor.SubGridCart.Length > 0 Then
                For iSub As Integer = 0 To Receptor.SubGridCart.Length - 1
                    If Receptor.SubGridCart(iSub).Selected = True Then
                        If DEPOS = True Then '干湿沉积
                            Index += 4 * 3 * Receptor.SubGridCart(iSub).Ynum * Receptor.SubGridCart(iSub).Xnum * nVer
                        End If
                    End If
                Next
            End If
            If DEPOS = True Then '干湿沉积
                Index += 4 * 3 * Receptor.DiscCarts.Length * nVer
            End If
            Index += 4
            OneLeng = Index  '求得每个记录的长度

            Dim binReader As New BinaryReader(File.Open(strFileName, FileMode.Open)) '打开要读取的文件
            Try
                '读取POST文件
                Dim Postvalue(OneLeng - 1) As Byte
                binReader.BaseStream.Position = IndexTime * OneLeng
                Dim count As Integer = binReader.Read(Postvalue, 0, OneLeng) '获取指定位置的数据
                Index = 0
                Index += 4 '跳过头文件
                '跳到给定个数的位置
                OnePostResult.m_dateD = BitConverter.ToInt32(Postvalue, Index) '读取日期
                Index += 4 + 4 + 8   '跳过平均小时数和所在组的ID
                ReDim OnePostResult.m_GridData(Receptor.SubGridCart(0).Ynum - 1, Receptor.SubGridCart(0).Xnum - 1) '主网格数据
                ReDim OnePostResult.m_SubGridData(Receptor.SubGridCart.Length - 1)
                For isub As Integer = 0 To Receptor.SubGridCart.Length - 1
                    ReDim OnePostResult.m_SubGridData(isub)(Receptor.SubGridCart(isub).Ynum - 1, Receptor.SubGridCart(isub).Xnum - 1)
                Next
                ReDim OnePostResult.m_CareData(Receptor.DiscCarts.Length - 1) '关心点数据
                If Receptor.SubGridCart(0).Selected = True Then
                    For k As Integer = 0 To Receptor.SubGridCart(0).Ynum - 1
                        For L As Integer = 0 To Receptor.SubGridCart(0).Xnum - 1
                            Dim ty As Double
                            If version = "07026" Then
                                ty = BitConverter.ToSingle(Postvalue, Index)
                            ElseIf version = "09292" Then
                                ty = BitConverter.ToDouble(Postvalue, Index)
                            End If
                            OnePostResult.m_GridData(Receptor.SubGridCart(0).Ynum - 1 - k, L).con = ty '读取网络浓度数据
                            Index += 4 * nVer
                        Next
                    Next
                End If
                For isub As Integer = 0 To Receptor.SubGridCart.Length - 1 '嵌套网格数据
                    If Receptor.SubGridCart(isub).Selected = True Then
                        For k As Integer = 0 To Receptor.SubGridCart(isub).Ynum - 1
                            For L As Integer = 0 To Receptor.SubGridCart(isub).Xnum - 1
                                OnePostResult.m_SubGridData(isub)(Receptor.SubGridCart(isub).Ynum - 1 - k, L).con = BitConverter.ToSingle(Postvalue, Index) '读取嵌套网格浓度数据
                                Index += 4 * nVer
                            Next
                        Next
                    End If
                Next
                For k As Integer = 0 To Receptor.DiscCarts.Length - 1
                    OnePostResult.m_CareData(k).con = BitConverter.ToSingle(Postvalue, Index) '读取关心点浓度数据
                    Index += 4 * nVer
                Next
                If Receptor.SubGridCart(0).Selected = True Then
                    If DEPOS = True Then '网格点的干湿沉积
                        Index += 4 * 3 * Receptor.SubGridCart(0).Ynum * Receptor.SubGridCart(0).Xnum * nVer
                    End If
                End If
                If DEPOS = True Then '关心点的干湿沉积
                    Index += 4 * 3 * Receptor.DiscCarts.Length * nVer
                End If
                Index += 4
            Catch ex As Exception
                binReader.Close()
                Return Nothing
            Finally
                binReader.Close()
            End Try

        End If
        Return OnePostResult
    End Function
    <OnDeserializing()> _
    Friend Sub OnDeserializingMethod(ByVal context As StreamingContext)

    End Sub

    <OnDeserialized()> _
    Friend Sub OnDeserializedMethod(ByVal context As StreamingContext)

    End Sub
End Class
